import java.util.ArrayList;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */

//给你一个单链表的头节点 head ，请你判断该链表是否为回文链表。如果是，返回 true ；否则，返回 false 。
class Solution {
    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    public boolean isPalindrome(ListNode head) {
        if(head==null||head.next==null){
            return true;
        }
        ArrayList<Integer> arr=new ArrayList<Integer>();
        while(head!=null){
            arr.add(head.val);
            head=head.next;
        }
        int i=0;
        int j=arr.size()-1;
        while(i<j){
            if(arr.get(i).compareTo(arr.get(j))!=0){
                return false;
            }
            ++i;
            --j;
        }
        return true;


    }
}